package com.njtoyo.taxi.admin.service.local_service.merchant.impl;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.cache.PrimaryCachePutter;
import com.njtoyo.taxi.admin.library.common.OperationRecordHelper;
import com.njtoyo.taxi.admin.mapper.master.entity.GeoDriverRegionArea;
import com.njtoyo.taxi.admin.mapper.master.entity.local_service.*;
import com.njtoyo.taxi.admin.mapper.master.enums.local_service.LifeAddressCategory;
import com.njtoyo.taxi.admin.mapper.master.enums.local_service.LifeMerchantAccountState;
import com.njtoyo.taxi.admin.mapper.master.mapper.GeoDriverRegionAreaMapper;
import com.njtoyo.taxi.admin.mapper.master.mapper.local_service.*;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeAddressPresenter;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeMerchantDetailsPresenter;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeMerchantPagePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.merchant.*;
import com.njtoyo.taxi.admin.service.local_service.merchant.MerchantService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import com.taxi.entity.common.ResultEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static cn.hutool.core.bean.BeanUtil.copyProperties;
import static cn.hutool.core.bean.BeanUtil.copyToList;
import static cn.hutool.core.util.ObjectUtil.isEmpty;
import static cn.hutool.core.util.ObjectUtil.isNotEmpty;
import static java.util.stream.Collectors.toList;

@Slf4j
@Service
public class MerchantServiceImpl implements MerchantService {

    @Autowired
    private OperationRecordHelper operationRecordHelper;

    @Autowired
    private LifeMerchantMapper lifeMerchantMapper;

    @Autowired
    private LifeAddressMapper lifeAddressMapper;

    @Autowired
    private LifeMerchantAddressMappingMapper lifeMerchantAddressMappingMapper;

    @Autowired
    private LifeMerchantAccountMapper lifeMerchantAccountMapper;

    @Autowired
    private LifeMerchantCommodityMapper lifeMerchantCommodityMapper;

    @Autowired
    private LifeMerchantAccountAddressMappingMapper lifeMerchantAccountAddressMappingMapper;

    @Autowired
    private LifeMerchantAlbumMapper lifeMerchantAlbumMapper;

    @Autowired
    private LifeMerchantMemberOrderMapper orderMapper;

    @Autowired
    private GeoMerchantRegionMapper regionAreaMapper;

    @Autowired
    private PrimaryCachePutter primaryCachePutter;

    @Autowired
    private GeoDriverRegionAreaMapper driverRegionAreaMapper;

    @Autowired
    private GeoMerchantRegionAreaMapper merchantRegionAreaMapper;


    /**
     * 所有商户all
     *
     * @param adminUser
     * @return
     */
    @Override
    public RestResult<List<LifeMerchant>> all(AdminUser adminUser) {
        switch (adminUser.getAccountType()) {
            case platform:
                break;
            default:
                return RestResult.failed("账号权限不够");
        }
        QueryWrapper<LifeMerchant> wrapper = new QueryWrapper<>();
        List<LifeMerchant> merchantList = lifeMerchantMapper.selectList(wrapper);
        return RestResult.success(merchantList);
    }

    /**
     * 司机运营区下商户列表
     *
     * @param driverRegionId
     * @return
     */
    @Override
    public RestResult<List<LifeMerchant>> allBydriverRegionId(Long driverRegionId) {
        //司机运营区->area->geo_merchant_region_area->商户->可赠送商品
        QueryWrapper<GeoDriverRegionArea> driverRegionAreaWrapper = new QueryWrapper<>();
        driverRegionAreaWrapper.select("area_id");
        driverRegionAreaWrapper.in("driver_region_id", driverRegionId);
        List<GeoDriverRegionArea> geoDriverRegionAreas = driverRegionAreaMapper.selectList(driverRegionAreaWrapper);
        List<LifeMerchant> merchantList = new ArrayList<>();
        if (isNotEmpty(geoDriverRegionAreas)) {
            List<Long> areaIds = geoDriverRegionAreas.stream().map(GeoDriverRegionArea::getAreaId).collect(toList());

            //商户运营区
            QueryWrapper<GeoMerchantRegionArea> merchantRegionWrapper = new QueryWrapper<>();
            merchantRegionWrapper.select("merchant_region_id");
            merchantRegionWrapper.in("area_id", areaIds);
            List<GeoMerchantRegionArea> regionAreaList = merchantRegionAreaMapper.selectList(merchantRegionWrapper);

            if (isNotEmpty(regionAreaList)) {
                List<Long> merchantRegionIds = regionAreaList.stream().map(GeoMerchantRegionArea::getMerchantRegionId).collect(toList());

                //商户id
                QueryWrapper<LifeMerchant> merchantWrapper = new QueryWrapper<>();
                merchantWrapper.in("merchant_region_id", merchantRegionIds);

                merchantList = lifeMerchantMapper.selectList(merchantWrapper);
            }
        }
        return RestResult.success(merchantList);
    }

    /**
     * 现有商户列表
     *
     * @param adminUser
     * @param wrapper
     * @return
     */
    @Override
    public RestResult<Page<LifeMerchantPagePresenter>> getPage(AdminUser adminUser, LifeMerchantQueryWrapper wrapper) {
        switch (adminUser.getAccountType()) {
            case platform:
                break;
            default:
                return RestResult.failed("账号权限不够");
        }
        Page<LifeMerchantPagePresenter> page = lifeMerchantMapper.getPage(wrapper);
        List<LifeMerchantPagePresenter> list = page.getRecords();
        if (isNotEmpty(list)) {
            //商家地址id
            List<Long> addressIds = list.stream()
                    .map(LifeMerchantPagePresenter::getAddressId).collect(toList());
            //本地生活运营区ids
            List<Long> merchantRegionIds = list.stream()
                    .map(LifeMerchantPagePresenter::getMerchantRegionId).collect(toList());

            //地址信息
            QueryWrapper<LifeAddress> lifeAddressWrapper = new QueryWrapper<>();
            lifeAddressWrapper.in("id", addressIds);
            List<LifeAddress> addressList = lifeAddressMapper.selectList(lifeAddressWrapper);

            //本地生活运营区geo_merchant_region
            QueryWrapper<GeoMerchantRegion> regionAreaWrapper = new QueryWrapper<>();
            regionAreaWrapper.select("id", "name");
            regionAreaWrapper.in("id", merchantRegionIds);
            List<Map<String, Object>> maps = regionAreaMapper.selectMaps(regionAreaWrapper);
            Map<Long, String> map = maps.stream().collect(Collectors.toMap(i -> Long.valueOf(i.get("id").toString()), i -> i.get("name").toString()));

            list.forEach(lifeMerchantPagePresenter -> {
                Long addressId = lifeMerchantPagePresenter.getAddressId();
                addressList.stream().filter(lifeAddress -> isNotEmpty(addressId)).filter(lifeAddress -> addressId.equals(lifeAddress.getId())).forEach(lifeAddress -> {
                    lifeMerchantPagePresenter.setAddress(lifeAddress.getAddress());
                    lifeMerchantPagePresenter.setContactPerson(lifeAddress.getContactPerson());
                    lifeMerchantPagePresenter.setContactPhone(lifeAddress.getContactPhone());
                    lifeMerchantPagePresenter.setAddressPoint(lifeAddress.getAddressPoint());
                    lifeMerchantPagePresenter.setOpeningTimestamp(lifeAddress.getOpeningTimestamp());
                    lifeMerchantPagePresenter.setCloseTimestamp(lifeAddress.getCloseTimestamp());
                });
                //商户地区
                lifeMerchantPagePresenter.setMerchantRegionName(map.getOrDefault(lifeMerchantPagePresenter.getMerchantRegionId(), null));
            });
        }
        return RestResult.success(page);
    }

    /**
     * 现有商户详情
     *
     * @param id
     * @return
     */
    @Override
    public RestResult<LifeMerchantDetailsPresenter> details(Long id) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }
        LifeMerchantDetailsPresenter result = copyProperties(lifeMerchant, LifeMerchantDetailsPresenter.class);

        //地址信息
        if (isNotEmpty(result)) {
            //修改商家地址0
            LifeMerchantAddressMapping lifeMerchantAddressMapping = lifeMerchantAddressMappingMapper.getAddressId(id);
            if (isNotEmpty(lifeMerchantAddressMapping)) {
                Long addressId = lifeMerchantAddressMapping.getAddressId();
                //商家地址id
                QueryWrapper<LifeAddress> addressWrapper = new QueryWrapper<>();
                addressWrapper.eq("id", addressId);
                addressWrapper.eq("category", 0);
                LifeAddress lifeAddress = lifeAddressMapper.selectOne(addressWrapper);
                result.setLifeAddress(lifeAddress);
            }
            List<Long> list = new ArrayList<>();
            Long merchantRegionId = result.getMerchantRegionId();
            list.add(merchantRegionId);
            //本地生活运营区
            QueryWrapper<GeoMerchantRegion> regionWrapper = new QueryWrapper<>();
            regionWrapper.select("id", "name");
            regionWrapper.eq("id", merchantRegionId);
            GeoMerchantRegion region = regionAreaMapper.selectOne(regionWrapper);
            if (isNotEmpty(region)) {
                result.setMerchantRegionName(region.getName());
            }
        }
        return RestResult.success(result);
    }

    /**
     * 添加现有商户
     *
     * @param adminUser
     * @param wrapper
     * @return
     */
    @Override
    @DSTransactional
    public RestResult add(AdminUser adminUser, LifeMerchantAddWrapper wrapper) {
        switch (adminUser.getAccountType()) {
            case platform:
                break;
            default:
                return RestResult.failed("账号权限不够");
        }
        //商户表
        LifeMerchant lifeMerchant = copyProperties(wrapper, LifeMerchant.class);
        lifeMerchantMapper.insert(lifeMerchant);
        Long id = lifeMerchant.getId();

        //添加地址
        LifeAddress lifeAddress = copyProperties(wrapper, LifeAddress.class);
        //默认商家地址
        lifeAddress.setCategory(LifeAddressCategory.merchant_address);
        lifeAddress.setPickupDelayDay(0);
        lifeAddressMapper.insert(lifeAddress);
        Long lifeAddressId = lifeAddress.getId();

        //商户地址关联
        LifeMerchantAddressMapping lifeMerchantAddressMapping = new LifeMerchantAddressMapping();
        lifeMerchantAddressMapping.setMerchantId(id);
        lifeMerchantAddressMapping.setAddressId(lifeAddressId);
        lifeMerchantAddressMappingMapper.insert(lifeMerchantAddressMapping);
        operationRecordHelper.addBusinessLog(String.format("新增了商户 [%d] 的信息", id));
        return RestResult.success();
    }

    /**
     * 修改现有商户
     *
     * @param wrapper
     * @return
     */
    @Override
    @DSTransactional
    public RestResult update(Long id, LifeMerchantUpdateWrapper wrapper) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }

        //商户
        new LambdaUpdateChainWrapper<>(lifeMerchantMapper)
                .eq(LifeMerchant::getId, id)
                .set(LifeMerchant::getMerchantRegionId, wrapper.getMerchantRegionId())
                .set(LifeMerchant::getDetail, wrapper.getDetail())
                .set(LifeMerchant::getName, wrapper.getName())
                .set(LifeMerchant::getLogo, wrapper.getLogo())
                .set(LifeMerchant::getLegalPerson, wrapper.getLegalPerson())
                .set(LifeMerchant::getProportion, wrapper.getProportion())
                .set(LifeMerchant::getCommodityAutoReview, wrapper.getCommodityAutoReview())
                .set(LifeMerchant::getUpdatedAt, new Date())
                .update();

        //修改商家地址0
        LifeMerchantAddressMapping lifeMerchantAddressMapping = lifeMerchantAddressMappingMapper.getAddressId(id);
        if (isNotEmpty(lifeMerchantAddressMapping)) {
            Long addressId = lifeMerchantAddressMapping.getAddressId();
            //地址详细信息
            new LambdaUpdateChainWrapper<>(lifeAddressMapper)
                    .eq(LifeAddress::getId, addressId)
                    .set(LifeAddress::getContactPerson, wrapper.getContactPerson())
                    .set(LifeAddress::getContactPhone, wrapper.getContactPhone())
                    .set(LifeAddress::getAddress, wrapper.getAddress())
                    .set(LifeAddress::getAddressPoint, wrapper.getAddressPoint())
                    .set(LifeAddress::getOpeningTimestamp, wrapper.getOpeningTimestamp())
                    .set(LifeAddress::getCloseTimestamp, wrapper.getCloseTimestamp())
                    .set(LifeAddress::getUpdatedAt, new Date())
                    .update();
        }
        operationRecordHelper.addBusinessLog(String.format("修改了商户 [%d] 的信息", id));
        return RestResult.success();
    }

    /**
     * 删除现有商户
     *
     * @param id
     * @return
     */
    @Override
    @DSTransactional
    public RestResult delete(Long id) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }

        //如果有商家账号处于激活 ,无法删除\
        QueryWrapper<LifeMerchantAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("merchant_id", id);
        wrapper.eq("state", LifeMerchantAccountState.active);
        Integer count = lifeMerchantAccountMapper.selectCount(wrapper);
        if (count > 0) {
            return RestResult.failed("存在商家账户正在激活使用中");
        }

        //存在订单,无法删除
        QueryWrapper<LifeMerchantMemberOrder> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.eq("merchant_id", id);
        Integer count1 = orderMapper.selectCount(orderQueryWrapper);
        if (count1 > 0) {
            return RestResult.failed("商家存在订单");
        }

        //删除商户相关的账号,商品
        lifeMerchantMapper.deleteById(id);

        //账号
        QueryWrapper<LifeMerchantAccount> accountQueryWrapper = new QueryWrapper<>();
        accountQueryWrapper.eq("merchant_id", id);
        lifeMerchantAccountMapper.delete(accountQueryWrapper);

        //账户关联地址
        QueryWrapper<LifeMerchantAccountAddressMapping> addressMappingAdress = new QueryWrapper<>();
        addressMappingAdress.eq("merchant_account_id", id);
        lifeMerchantAccountAddressMappingMapper.delete(addressMappingAdress);

        //商品
        QueryWrapper<LifeMerchantCommodity> commodityQueryWrapper = new QueryWrapper<>();
        commodityQueryWrapper.eq("merchant_id", id);
        lifeMerchantCommodityMapper.delete(commodityQueryWrapper);

        //商户地址关联
        QueryWrapper<LifeMerchantAddressMapping> addressMappingQueryWrapper = new QueryWrapper<>();
        addressMappingQueryWrapper.eq("merchant_id", id);
        lifeMerchantAddressMappingMapper.delete(addressMappingQueryWrapper);

        //商户相册表life_merchant_album
        QueryWrapper<LifeMerchantAlbum> albumQueryWrapper = new QueryWrapper<>();
        addressMappingQueryWrapper.eq("merchant_id", id);
        lifeMerchantAlbumMapper.delete(albumQueryWrapper);

        operationRecordHelper.addBusinessLog(String.format("删除了商户 [%d] 的信息", id));
        return RestResult.success();
    }


    /**
     * 自提点列表
     *
     * @param id
     * @return
     */
    @Override
    public RestResult<List<LifeAddress>> getSelfPage(Long id) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }
        //关联的地址
        QueryWrapper<LifeMerchantAddressMapping> wrapper = new QueryWrapper<>();
        wrapper.eq("merchant_id", id);
        List<LifeMerchantAddressMapping> mappingList = lifeMerchantAddressMappingMapper.selectList(wrapper);

        //商家地址id
        List<Long> addressIds = mappingList.stream()
                .map(LifeMerchantAddressMapping::getAddressId).collect(toList());

        QueryWrapper<LifeAddress> lifeAddressWrapper = new QueryWrapper<>();
        lifeAddressWrapper.in("id", addressIds);
        lifeAddressWrapper.ne("category", 0);
        List<LifeAddress> addressList = lifeAddressMapper.selectList(lifeAddressWrapper);

        return RestResult.success(addressList);
    }

    /**
     * 不属于这个商户的自提点列表
     *
     * @param id
     * @return
     */
    @Override
    public RestResult<List<LifeAddress>> noBelongPickup(Long id) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }

        //符合商家的地址
        QueryWrapper<LifeMerchantAddressMapping> wrapper = new QueryWrapper<>();
        wrapper.eq("merchant_id", id);
        List<LifeMerchantAddressMapping> list = lifeMerchantAddressMappingMapper.selectList(wrapper);
        if (isEmpty(list)) {

        }
        List<Long> addressId = list.stream().map(LifeMerchantAddressMapping::getAddressId).collect(toList());

        //关联的地址剔除同样的商户,地址
        List<LifeAddress> addressList = lifeAddressMapper.notInMerchant(id);

        return RestResult.success(addressList);

    }

    /**
     * 自提点添加
     *
     * @param id
     * @param wrapper
     * @return
     */
    @Override
    public RestResult addSelf(Long id, PickupLocationAddWrapper wrapper) {
        Boolean flag = wrapper.getFlag();
        //true:添加已有自提点
        if (flag) {
            log.info("对已有的自提点进行绑定");
            //商户地址关联
            Long selfId = wrapper.getSelfId();
            if (isEmpty((wrapper.getSelfId()))) {
                return RestResult.failed("请填写自提点信息");
            }
            LifeMerchantAddressMapping lifeMerchantAddressMapping = new LifeMerchantAddressMapping();
            lifeMerchantAddressMapping.setMerchantId(id);
            lifeMerchantAddressMapping.setAddressId(selfId);
            lifeMerchantAddressMappingMapper.insert(lifeMerchantAddressMapping);
            operationRecordHelper.addBusinessLog(String.format("商户 [%d] 新绑定了自提点信息", id));
        } else {
            log.info("新增自提点");
            LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
            if (isEmpty(lifeMerchant)) {
                return RestResult.build(ResultEnum.NOT_FOUND);
            }
            //添加地址
            LifeAddress lifeAddress = copyProperties(wrapper, LifeAddress.class);
            lifeAddress.setName(lifeMerchant.getName());
            //自提点
            lifeAddress.setCategory(LifeAddressCategory.pickup_location);
            //延迟天数
            lifeAddress.setPickupDelayDay(0);
            lifeAddressMapper.insert(lifeAddress);
            Long lifeAddressId = lifeAddress.getId();

            //商户地址关联
            LifeMerchantAddressMapping lifeMerchantAddressMapping = new LifeMerchantAddressMapping();
            lifeMerchantAddressMapping.setMerchantId(id);
            lifeMerchantAddressMapping.setAddressId(lifeAddressId);
            lifeMerchantAddressMappingMapper.insert(lifeMerchantAddressMapping);
            operationRecordHelper.addBusinessLog(String.format("新增了商户 [%d] 的自提点信息", id));
        }
        return RestResult.success();
    }

    /**
     * 商户添加多个未绑定的自提点
     *
     * @param id
     * @return
     */
    @Override
    public RestResult addSelfs(Long id, PickupLocationAddsWrapper wrapper) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }
        //自提点只能新增，不能删除。
        List<Long> addressIds = wrapper.getAddressIds();
        //商户关联的地址
        QueryWrapper<LifeMerchantAddressMapping> addressMappingQueryWrapper = new QueryWrapper<>();
        addressMappingQueryWrapper.eq("merchant_id", id);
        List<LifeMerchantAddressMapping> mappingList = lifeMerchantAddressMappingMapper.selectList(addressMappingQueryWrapper);

        //商家地址id
        List<Long> addressIds1 = mappingList.stream().map(LifeMerchantAddressMapping::getAddressId).collect(toList());

        //参数是否包含已有的自提点地址ID
//        addressIds.retainAll(addressIds1);
//        if (addressIds.size() > 0) {
//            return RestResult.failed("不能添加已有的自提点");
//        }

        addressIds.forEach(addressId -> {
            LifeMerchantAddressMapping lifeMerchantAddressMapping = new LifeMerchantAddressMapping();
            lifeMerchantAddressMapping.setMerchantId(id);
            lifeMerchantAddressMapping.setAddressId(addressId);
            lifeMerchantAddressMapping.setCreatedAt(new Date());
            lifeMerchantAddressMapping.setUpdatedAt(new Date());
            lifeMerchantAddressMappingMapper.insert(lifeMerchantAddressMapping);
            operationRecordHelper.addBusinessLog(String.format("商户 [%d] 添加自提点了 [%d] 的信息", id, addressId));
        });

        return RestResult.success();
    }

    /**
     * 获取所有地址的ids，不需要区分自提点和商家地址。
     */
    @Override
    public RestResult<List<LifeAddressPresenter>> address(Long id) {
        LifeMerchant lifeMerchant = lifeMerchantMapper.selectById(id);
        if (isEmpty(lifeMerchant)) {
            return RestResult.build(ResultEnum.NOT_FOUND);
        }
        QueryWrapper<LifeMerchantAddressMapping> lifeMerchantAddressMappingQueryWrapper = new QueryWrapper<>();
        lifeMerchantAddressMappingQueryWrapper.in("merchant_id", id);
        List<LifeMerchantAddressMapping> list = lifeMerchantAddressMappingMapper.selectList(lifeMerchantAddressMappingQueryWrapper);
        List<LifeAddressPresenter> result = copyToList(list, LifeAddressPresenter.class);

        if (isNotEmpty(result)) {
            //地址名
            QueryWrapper<LifeAddress> lifeAddressWrapper = new QueryWrapper<>();
            List<LifeAddress> addressList = lifeAddressMapper.selectList(lifeAddressWrapper);

            result.forEach(addressPresenter -> {
                Long addressId = addressPresenter.getAddressId();
                addressPresenter.setName(lifeMerchant.getName());

                //地址
                addressList.forEach(lifeAddress -> {
                    Long lifeAddressId = lifeAddress.getId();
                    if (lifeAddressId.equals(addressId)) {
                        addressPresenter.setAddressName(lifeAddress.getName());
                        addressPresenter.setCategory(lifeAddress.getCategory());
                    }
                });
            });
        }
        return RestResult.success(result);
    }


    /**
     * 自提点分页列表展示
     *
     * @param adminUser
     * @return
     */
    @Override
    public RestResult<Page<LifeAddress>> pickUpPage(AdminUser adminUser, PickupLocationPageWrapper wrapper) {
        switch (adminUser.getAccountType()) {
            case platform:
                break;
            default:
                return RestResult.failed("账号权限不够");
        }
        Page<LifeAddress> lifeAddressPage = lifeAddressMapper.pickUpPage(wrapper);
        return RestResult.success(lifeAddressPage);
    }

    /**
     * 自提点不分页列表展示
     *
     * @param adminUser
     * @return
     */
    @Override
    public RestResult<List<LifeAddress>> pickUplist(AdminUser adminUser) {
        switch (adminUser.getAccountType()) {
            case platform:
                break;
            default:
                return RestResult.failed("账号权限不够");
        }
        QueryWrapper<LifeAddress> lifeAddressWrapper = new QueryWrapper<>();
        lifeAddressWrapper.ne("category", 0);
        List<LifeAddress> addressList = lifeAddressMapper.selectList(lifeAddressWrapper);
        return RestResult.success(addressList);
    }

    /**
     * 自提点设置
     *
     * @param wrapper@return
     */
    @Override
    public RestResult setUp(PickupLocationSetUpAddWrapper wrapper) {
        LifeAddress lifeAddress = copyProperties(wrapper, LifeAddress.class);
        //自提点
        lifeAddress.setCategory(LifeAddressCategory.pickup_location);
        lifeAddressMapper.insert(lifeAddress);
        Long lifeAddressId = lifeAddress.getId();
        operationRecordHelper.addBusinessLog(String.format("添加自提点了 [%d] 的信息", lifeAddressId));
        return RestResult.success();
    }


}
